package com.finalist.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.finalist.dao.AreaStandardCodeDao;
import com.finalist.entity.AreaStandardCode;
/**
 * Dao - 地区代码
 * 
 * @author Finalist IT Group
 * @version 3.0
 */
@Repository("areaStandardCodeDaoImpl")
public class AreaStandardCodeDaoImpl extends BaseDaoImpl<AreaStandardCode, Long> implements AreaStandardCodeDao{
	@PersistenceContext
	protected EntityManager entityManager;
	/**
     * 根据地区名称和城市级别查找地区代码
     * cityLevel 城市级别
     * areaName 地区名称
     * @return 城市对象
     */
	@Override
	public String findAreaCode(String areaLevel, String areaName) {
		String jpql = "select areaStandardCode.areaCode from AreaStandardCode areaStandardCode where areaStandardCode.areaLevel = :areaLevel and areaStandardCode.areaName = :areaName";
        String query = entityManager.createQuery(jpql, String.class)
        		.setFlushMode(FlushModeType.COMMIT)
        		.setParameter("areaLevel", areaLevel)
        		.setParameter("areaName", areaName)
        		.getSingleResult();
        return query;
	}
	

}
